package com.leyou.auth.interceptors;

import com.leyou.auth.config.JwtProperties;
import com.leyou.auth.task.GetTokenInTime;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@EnableConfigurationProperties(JwtProperties.class)
public class TokenInterceptor implements RequestInterceptor {

    @Autowired
    private JwtProperties props;

    @Autowired
    private GetTokenInTime getTokenInTime;

    @Override
    public void apply(RequestTemplate template) {
        //给feign的请求添加，请求头
        template.header(props.getApp().getHeaderName(),getTokenInTime.getToken());
    }
}
